package com.supermarket.api.web.admin;

import com.supermarket.api.bean.collection.CollectionReq;
import com.supermarket.api.bean.collection.CollectionRes;
import com.supermarket.api.common.BaseResponse;
import com.supermarket.api.common.PageParam;
import com.supermarket.api.entity.CollectionEntity;
import com.supermarket.api.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户收藏接口
 * @author 李其伟
 * @date 2023/11/10
 */
@Controller
@RequestMapping("/admin/collection")
public class AdminCollectionController {

    /**
     * 用户收藏服务层
     */
    @Autowired
    private CollectionService collectionService;

    @ResponseBody
    @PostMapping("/createAndDelete")
    public String createAndDelete(@Valid @RequestBody CollectionReq req){
        collectionService.createAndDelete(req);
        return BaseResponse.successJson();
    }

    @ResponseBody
    @PostMapping("/clear")
    public String clear(){
        collectionService.clear();
        return BaseResponse.successJson();
    }

    @ResponseBody
    @GetMapping("/detail/{sku}")
    public String detail(@PathVariable String sku){
        CollectionEntity collectionEntity = collectionService.detail(sku);
        return BaseResponse.successJson(collectionEntity);
    }


    @ResponseBody
    @GetMapping("/list")
    public String list(PageParam pageParam){
        Page<CollectionRes> page = collectionService.list(pageParam);
        return BaseResponse.successJson(page);
    }

}
